<?php
// require_once("dao/db/db.php"); 
// require_once("dao/db/expression.php"); 
class daobase extends db{
	public function __construct(){
		parent::__construct();
	}
	/**
	 * exclude sql sentence return result
	 * 
	 * @param  $sql exclude sql sentence
	 * return $data
	 * 
	 */
	public function fetchit($sql){
		return $this->fetchAll($sql,'MYSQL_BOTH');
	}
	/**
	 * exclude sql sentence
	 *
	 * @param  $sql exclude sql sentence
	 * 
	 */
	public function queryit($sql){
		$query = $this->query($sql);
		return $query;
	}
	/**
	 * 获取客户端IP
	 * 
	 */
	public function getIp(){
		//php获取ip的算法
		$ip ="";
		if($_SERVER['REMOTE_ADDR']){
			$ip=$_SERVER['REMOTE_ADDR'];
		}else if($_SERVER['REMOTE_HOST']){
			$ip=$_SERVER['REMOTE_HOST'];
		}
		else 
		{ 
			 $ip = "Unknown"; 
		} 
			return $ip ; 

	}
	public function recordIp($table,$colum,$userId,$field='id'){
		$oldIps=$this->select($table,$colum)
		->where($table.".".$field."='$userId'")
		->fetchAll();
		$oldIps=$oldIps[0][$colum];
		if($oldIps){
			$newIps=$oldIps.",".($this->getIp());
		}else{
			$newIps=$this->getIp();
		}
		$update = $this->update($table,$colum,$newIps)
		->where($table.".".$field."='$userId'")
		->query();
		return $this->sqlQuery;
	}
}